// ==============================================================================
//
// software development kit v 3.0
// shared structures unit
//
// copyright (c) 2008-2009 gear pair games
//
// copyright and license exceptions noted in source
//
// description: this struct(s) unit, .
// ==============================================================================
unit convertApi;

interface

uses
  cls,
  types,
  main,
  xml,
  draw,
  structs;

type
// CConverter
  CConverter = class( CObject )
  private
    fFile : CXML;
    fdraw : drawMesh;
// CConverter::parse
    procedure parse( const inXml : CXML );
  public { public }
// CConverter::doInit
    procedure doInit; override;
// CConverter::doFree
    procedure doFree; override;
// CConverter::doMessage
    procedure doMessage( var inMsg : structMsg ); override;
    procedure doDraw; override;
  end;

implementation

uses
  msg,
  math,
  enums,
  headers;
{ CConverter }

// CConverter::doFree
procedure CConverter.doDraw;
begin
//
  INotifier( notifier ).renderer.drawApi.drawCustom( drwVertexes, @fdraw );
  inherited;
end;

procedure CConverter.doFree;
begin
// freemem
  freemem( fdraw.verts );
  freemem( fdraw.norm );
  freemem( fdraw.faces );
  inherited;
end;

// CConverter::doInit
procedure CConverter.doInit;
begin
  inherited;
end;

// CConverter::doMessage
procedure CConverter.doMessage( var inMsg : structMsg );
var
  tmp : void;
begin
// accept msh
  case inMsg.msg of
    msgConvert :
     begin
     tmp := INotifier( notifier ).filesys.getfile( inMsg.asHandle );
     fFile := CXML.Create( tmp, true );
     parse( fFile );
     fFile.Destroy;
// fFile.
     end;
  end;
// next
  inherited;
end;

// CConverter::parse
procedure CConverter.parse( const inXml : CXML );
var
  i : int;
begin
// export
  if inXml.tag <> 'export' then
    exit;
// text to vec3
  for i := 0 to inXml.count - 1 do
   begin
// export               // todo: rename "vert" to "verts"
   fdraw.cntV:= textToVec3( fdraw.verts, inXml.nodeI[ i ][ 'verts' ].content );
   // export               // todo: rename "vert" to "verts"
   textToVec3( fdraw.norm, inXml.nodeI[ i ][ 'normals' ].content );
//   calcTangentSpace(fdraw.verts^, fdraw.);
// export
   fdraw.cntF:= textToFaces( fdraw.faces, inXml.nodeI[ i ][ 'faces' ].content );
   end;
end;

end.
